﻿using System;
using System.Collections.Generic;

namespace Firefly.Framework.ContentManagement
{
    public class AssetTracker
    {
        public event EventHandler<AssetChangedEventArgs> AssetChanged;

        public string AssetName { get; set; }
        public object Asset { get; set; }
        public List<IDisposable> Disposables { get; set; }
        public int RefCount { get; set; }
        public AssetStatus Status { get; set; }
        public List<string> RefersTo { get; set; }
        public List<string> ReferredToBy { get; set; }

        public AssetTracker()
        {
            Disposables = new List<IDisposable>();
            Status = AssetStatus.Disposed;
            RefersTo = new List<string>();
            ReferredToBy = new List<string>();
        }

        public void TrackDisposableAsset(IDisposable disposable)
        {
            Disposables.Add(disposable);
        }

        public void NotifyAssetChanged(AssetChangedEventArgs e)
        {
            EventHandler<AssetChangedEventArgs> handler = AssetChanged;

            if (handler != null)
            {
                handler(this, e);
            }
        }
    }
}
